<template>
	<view class="container">
		<view style="text-align: center;">
			<image :src="imagesrc" :mode="widthFix" style="text-align: center;width: 300upx;height: 300upx;margin-top: 100upx;margin-bottom: 100upx;border-radius: 20px;"></image>
		</view>

		<view class="list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">我的昵称</text>
			<input class="input" placeholder="用户昵称" maxlength="50" style="text-align: right;" placeholder-class="placeholder"
			 v-model="name" />
		</view>

		<view class="list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">性别</text>


			<radio-group @change="radioChange">
				<view class="uni-padding-wrap">
					<view>
						<label class="radio">
							<radio value="1" checked="true" />男</label>
						<label class="radio">
							<radio value="2" />女</label>
					</view>
				</view>
			</radio-group>


		</view>




		<view class="list-cell log-out-btn" @click="toChangeNick">
			<text class="cell-tit-tit">确认修改</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				name: '0',
				sex: 1,
				imagesrc: ''

			};
		},
		computed: {
			...mapState(['userInfo', 'token'])
		},
		methods: {
			...mapMutations(['logout']),
			radioChange: function(evt) {
				console.log(evt)
				this.sex = Number(evt.detail.value)

			},
			onShow() {
				this.name = this.userInfo.Nick
			},
			onLoad() {

				let _this = this


				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes.authResult);
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							success: function(infoRes) {
								_this.imagesrc = infoRes.userInfo.avatarUrl

							}
						});
					},
					fail: function(e) {
						uni.showModal({
							content: e,
							showCancel: false
						})
					}
				});
			},


			navTo(url) {
				uni.navigateTo({
					url
				})
			},
			//退出登录
			toChangeNick() {
				// 修改昵称


				if (this.userInfo && this.userInfo.MemId) {
					console.log("set/")

					uni.request({
						url: this.$serverUrl + '/app/member/changeBaseInfo',
						header: {
							"Content-Type": "application/json",
							"Authorization": this.token
						},
						data: {
							"mem_id": this.userInfo.MemId,
							"sex": this.sex,
							"nick": this.name,
							"head_img_url": this.imagesrc
						},
						method: "POST",
						success: (e) => {
							if (e.data.success) {
								this.$api.msg(`修改成功`);

							} else {
								console.log(e.data.message)
							}

						},
						fail: (e) => {

							this.$api.msg(`错误`);
							console.log(e.errMsg)
						}
					})
				}













			},
			//switch
			switchChange(e) {
				let statusTip = e.detail.value ? '打开' : '关闭';
				this.$api.msg(`${statusTip}消息推送`);
			},

		}
	}
</script>

<style lang='scss'>
	page {
		background: $page-color-base;
	}

	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx $page-row-spacing;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 40upx;

			.cell-tit {
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}

			.cell-tit-tit {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 690upx;
				height: 80upx;
				margin: 60upx auto;
				font-size: $font-lg;
				color: #fff;
				background-color: $base-color;
				border-radius: 10upx;
				box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);

			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: $font-lg;
			color: $font-color-light;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: $font-base;
			color: $font-color-light;
		}

		switch {
			transform: translateX(16upx) scale(.84);
		}
	}
</style>
